﻿namespace ShadowCode;
public readonly struct TransformData(GeneratorSyntaxContext context)
{
    public readonly GeneratorSyntaxContext Context = context;

    public SemanticModel SemanticModel => Context.SemanticModel;

    public Compilation Compilation => SemanticModel.Compilation;

    public SyntaxTree SyntaxTree => SyntaxNode.SyntaxTree;

    public SyntaxNode SyntaxNode => Context.Node;

    public ISymbol? GetSymbolInfo(SyntaxNode node)
    {
        var res = SemanticModel.GetSymbolInfo(node);
        return res.Symbol ?? res.CandidateSymbols.FirstOrDefault();
    }

    public ITypeSymbol? GetTypeSymbol(SyntaxNode node) =>
        SemanticModel.GetTypeInfo(node).Type;

    public ISymbol? GetDeclaredSymbol(SyntaxNode node) =>
        SemanticModel.GetDeclaredSymbol(node);

    public Optional<object?> GetConstantValue(SyntaxNode node) =>
        SemanticModel.GetConstantValue(node);

    public string? GetConstantStringValue(SyntaxNode node) =>
        GetConstantValue(node).Value?.ToString();  
}
